﻿using MediatR;
using Traceability.App.API.Application.Command.Img;
using Traceability.App.Domain.Traceability;
using Traceability.App.ErrorCode;
using Traceability.App.Infrastructrue.Interface;

namespace Traceability.App.API.Application.Handler.Img
{
    public class GetImgHandler : IRequestHandler<GetImgCommand, APIResult<List<ImgInformationModel>>>
    {
        private readonly IBaseRepository<ImgInformationModel> imgRepo;

        public GetImgHandler(IBaseRepository<ImgInformationModel> imgRepo)
        {
            this.imgRepo = imgRepo;
        }
        public Task<APIResult<List<ImgInformationModel>>> Handle(GetImgCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<ImgInformationModel>> result = new APIResult<List<ImgInformationModel>>();
            var res = imgRepo.GetAll().Where(x => x.Batch == request.Batch && x.ImgType == request.imgType).ToList();
            result.Message = "查询成功";
            result.Data = res;
            result.Code = APIEnum.Ok;
            return Task.FromResult(result);
        }
    }
}
